package com.slliver.order.controller;


import com.slliver.order.feign.ProductFeignService;
import com.slliver.order.feign.StockFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private ProductFeignService productFeignService;

    @Autowired
    private StockFeignService stockFeignService;

    @GetMapping("/test")
    public String test(){
        System.out.println("订单服务调用success...");
        String msg = stockFeignService.test();
        return "Hello world springcloudAlibaba order service call stock service test result is ==>> " + msg;
    }

    // http://192.168.31.111:8087/order/get/stock/123
    @GetMapping("/get/stock/{id}")
    public String getStock(@PathVariable("id") Long id){
        System.out.println("订单服务调用库存success...");
        String msg = stockFeignService.get(id);
        return "Hello Feign ==>> " + msg;
    }

    // http://192.168.31.111:8087/order/get/product/123
    @GetMapping("/get/product/{id}")
    public String getProduct(@PathVariable("id") Long id){
        System.out.println("订单服务调用商品success...");
        String msg = productFeignService.get(id);
        return "Hello Feign ==>> " + msg;
    }

}
